/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JFEnviarEmail.java
 *
 * Created on 29/11/2012, 21:21:40
 */
package contatospro;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.MessagingException;
/**
 *
 * @author Junnyor S2 Rafa
 */
public class JFEnviarEmail extends javax.swing.JFrame {

    /** Creates new form JFEnviarEmail */
    public JFEnviarEmail() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        smtpjTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        remetentejTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        usuariojTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        parajTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        assuntojTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        corpojTextArea = new javax.swing.JTextArea();
        senhajTextField = new javax.swing.JPasswordField();
        jToolBar1 = new javax.swing.JToolBar();
        emailjButton = new javax.swing.JButton();
        cancelarjButton = new javax.swing.JButton();

        setTitle("Enviar Email ...");

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel1.setText("SMTP:");

        smtpjTextField.setEditable(false);
        smtpjTextField.setText("smtp.gmail.com");

        jLabel2.setText("Email Remetente:");

        jLabel3.setText("Usuário do Email:");

        jLabel4.setText("Senha do Email:");

        jLabel5.setText("Para:");

        jLabel6.setText("Assunto:");

        jLabel7.setText("Texto:");

        corpojTextArea.setColumns(20);
        corpojTextArea.setRows(5);
        jScrollPane1.setViewportView(corpojTextArea);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(141, 141, 141)
                        .addComponent(jLabel4))
                    .addComponent(jLabel1)
                    .addComponent(smtpjTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(usuariojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(senhajTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE))
                    .addComponent(jLabel5)
                    .addComponent(parajTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                    .addComponent(jLabel6)
                    .addComponent(assuntojTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                    .addComponent(jLabel7)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                    .addComponent(remetentejTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                    .addComponent(jLabel2))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(smtpjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(remetentejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(usuariojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(senhajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(parajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(assuntojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar1.setFloatable(false);

        emailjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/contatospro/Icones/Enviar email-.png"))); // NOI18N
        emailjButton.setText("Enviar");
        emailjButton.setToolTipText("Enviar Email");
        emailjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        emailjButton.setIconTextGap(6);
        emailjButton.setMaximumSize(new java.awt.Dimension(65, 60));
        emailjButton.setPreferredSize(new java.awt.Dimension(65, 60));
        emailjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        emailjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                emailjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(emailjButton);

        cancelarjButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/contatospro/Icones/cancelar.png"))); // NOI18N
        cancelarjButton.setText("Cancelar");
        cancelarjButton.setToolTipText("Cancelar ");
        cancelarjButton.setFocusable(false);
        cancelarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cancelarjButton.setMaximumSize(new java.awt.Dimension(65, 60));
        cancelarjButton.setPreferredSize(new java.awt.Dimension(65, 60));
        cancelarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cancelarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(cancelarjButton);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(49, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-514)/2, (screenSize.height-538)/2, 514, 538);
    }// </editor-fold>//GEN-END:initComponents

private void emailjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emailjButtonActionPerformed
// TODO add your handling code here:
     try {
            Funcoes.sendEmail(
                      remetentejTextField.getText()
                    , smtpjTextField.getText()
                    , usuariojTextField.getText()
                    , senhajTextField.getText()
                    , assuntojTextField.getText()        
                    , parajTextField.getText()
                    , ""
                    , corpojTextArea.getText()
                    
                    );
        } catch (MessagingException ex) {
            Logger.getLogger(JFEnviarEmail.class.getName()).log(Level.SEVERE, null, ex);
        }
                     remetentejTextField.setText(""); 
                     usuariojTextField.setText(""); 
                     senhajTextField.setText("");
                     assuntojTextField.setText(""); 
                     parajTextField.setText("");
                     corpojTextArea.setText(""); 
                  
                   if (
                     remetentejTextField.getText().equals(""));
                     usuariojTextField.getText().equals(""); 
                     senhajTextField.getText().equals("");
                     assuntojTextField.getText().equals(""); 
                     parajTextField.getText().equals("");
                     corpojTextArea.getText().equals("");
                     
                     return;
                   
}//GEN-LAST:event_emailjButtonActionPerformed

private void cancelarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarjButtonActionPerformed
// TODO add your handling code here:
                 this.dispose();
}//GEN-LAST:event_cancelarjButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JFEnviarEmail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JFEnviarEmail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JFEnviarEmail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JFEnviarEmail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new JFEnviarEmail().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField assuntojTextField;
    private javax.swing.JButton cancelarjButton;
    private javax.swing.JTextArea corpojTextArea;
    private javax.swing.JButton emailjButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTextField parajTextField;
    private javax.swing.JTextField remetentejTextField;
    private javax.swing.JPasswordField senhajTextField;
    private javax.swing.JTextField smtpjTextField;
    private javax.swing.JTextField usuariojTextField;
    // End of variables declaration//GEN-END:variables
}
